package org.goldfish.chatroom.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.goldfish.chatroom.entity.PublicNetworkService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.lang.NonNull;

import java.util.List;

@Mapper

public interface PublicNetworkServiceMapper {
    List<PublicNetworkService> getPublicNetworkServiceList();

    @Nullable
    PublicNetworkService getPublicNetworkServiceByName(String name);

    void insertPublicNetworkService(@NonNull PublicNetworkService service);

    void deletePublicNetworkService(String name);

    void updatePublicNetworkService(@NotNull PublicNetworkService publicNetworkService);

    default void updatePublicNetworkService(@NotNull PublicNetworkService publicNetworkService, boolean insert){
        PublicNetworkService old = getPublicNetworkServiceByName(publicNetworkService.getName());
        if (old == null) {
            if (insert) {
                insertPublicNetworkService(publicNetworkService);
            }
        } else {
            updatePublicNetworkService(publicNetworkService);
        }
    }

}
